package com.itheima.appserver.excepiton;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @author yaohu
 * @date 2021/12/3
 * @Version 1.0
 * @describe
 */
@ControllerAdvice
public class ExceptionHandlers {

    @ExceptionHandler(BusinessException.class)
    public ResponseEntity businessException(BusinessException e) {
        // 响应500
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getErrorResult());
    }

    @ExceptionHandler(Exception.class)
    public ResponseEntity exception(Exception e) {
        e.printStackTrace();
        // 相应500
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ErrorResult.error());
    }
}
